<!DOCTYPE html>
<html>
<head>
    <title>客户</title>
        <#include "../../include/head-file.ftl">
</head>
<body>
<div id="index" class="ms-index" v-cloak>
        <el-header class="ms-header" height="50px">
        <el-col :span=12>
            <@shiro.hasPermission name="game:user:save">
                <el-button type="primary" class="el-icon-plus" size="default" @click="save()">新增</el-button>

            </@shiro.hasPermission>
            <@shiro.hasPermission name="game:user:del">
                <el-button type="danger" class="el-icon-delete" size="default" @click="del(selectionList)"  :disabled="!selectionList.length">删除</el-button>
            </@shiro.hasPermission>
        </el-col>
        </el-header>
            <div class="ms-search">
                <el-row>
                    <el-form :model="form"  ref="searchForm"  label-width="120px" size="default">
                            <el-row>
                                            <el-col :span=8>
            <!--玄乐账号-->

	        <el-form-item  label="玄乐账号" prop="xl">
	            <el-input
                        v-model="form.xl"
                         :disabled="false"
                          :readonly="false"
                          :style="{width:  '100%'}"
                          :clearable="true"
                        placeholder="请输入玄乐账号">
                </el-input>
	        </el-form-item>   
                                            </el-col>
                                    <el-col :span=16 style="display: flex;justify-content: end;padding-right: 10px;">
                                        <el-button type="primary" class="el-icon-search" size="default" @click="currentPage=1;list(true)">搜索</el-button>
                                        <el-button @click="rest"  class="el-icon-refresh" size="default">重置</el-button>
                                        <ms-search ref="search" @search="search" :search-json="searchJson" :search-key="historyKey"></ms-search>
                                    </el-col>
                            </el-row>
                    </el-form>
                </el-row>
            </div>
    <el-main class="ms-container">
        <el-table class="ms-table-pagination" v-loading="loading" ref="multipleTable" border :data="dataList" tooltip-effect="dark" @selection-change="handleSelectionChange">
                <template #empty>
                    {{emptyText}}
                </template>
                    <el-table-column type="selection" width="40" :selectable="isChecked"></el-table-column>
                            <el-table-column label="玄乐账号"   align="left" prop="xl">
                            </el-table-column>
                    <el-table-column label="金钱"  align="left" prop="moneyLz" >
                        <template #default="{ row }">
                            <div class="cell-content">
                                {{ ms.util.moneyFormatter(row.moneyLz)}}
                            </div>
                        </template>
                    </el-table-column>
                        <el-table-column label="区长"   align="left" prop="selectCodes" :formatter="selectCodesFormat">
                        </el-table-column>
                    <el-table-column label="操作"  width="180" align="center" fixed="right">
                            <template #default="scope">
                                <@shiro.hasPermission name="game:user:update">
                                    <el-link type="primary" :underline="false" @click="save(scope.row.id)">编辑</el-link>
                                </@shiro.hasPermission>
                            <@shiro.hasPermission name="game:user:del">
                                <el-link type="primary" :underline="false" @click="del([scope.row])" v-if="scope.row.del!=3">删除</el-link>
                            </@shiro.hasPermission>
                </template>
                </el-table-column>
            </el-table>
                <el-pagination
                        background
                        :page-sizes="[10,20,30,40,50,100]"
                        layout="total, sizes, prev, pager, next, jumper"
                        :current-page="currentPage"
                        :page-size="pageSize"
                        :total="total"
                        class="ms-pagination"
                        @current-change='currentChange'
                        @size-change="sizeChange">
                </el-pagination>
    </el-main>
</div>

</body>

</html>
<script>
    var indexVue = new _Vue({
        el: '#index',
		provide() {
			return {
				searchParent: this //筛选使用
			};
		},
        data:function() {
            return {
				        searchJson:[
        //玄乐账号
        {'isSearch':'true','action':'and', 'field': 'XL', 'el': 'eq', 'model': 'xl', 'name': '玄乐账号', 'type': 'input'},
        // 金钱
        {action:'and', field: 'MONEY_LZ', el: 'eq', model: 'moneyLz', name: '金钱', type: 'number'},
        // 区长
        {'isSearch':'','action':'and', 'field': 'SELECT_CODES', 'el': 'eq', 'model': 'selectCodes', 'name': '区长', 'key': 'value', 'title': 'label', 'type': 'select', 'multiple': false},
                ],
                dataList: [], //客户列表
                selectionList:[],//客户列表选中
                total: 0, //总记录数量
                pageSize: 10, //页面数量
                currentPage:1, //初始页
                manager: ms.manager,
                loading: true,//加载状态
                emptyText:'',//提示文字
                // 区长
                selectCodesOptions:[{"value":"code","label":"区长"},{"value":"city","label":"市长"},{"value":"","label":""}],
                //搜索表单
                form:{
                    sqlWhere:null
                },
                //历史记录参数
                historyKey: "game_user_history"
            }
        },
        watch:{

        },
        methods:{
            isChecked: function(row) {
                if(row.del == 3) {
                    return false;
                }
                return true;
            },
            //查询列表
            list: function(isSearch) {
                var that = this;
                var data = {}; //搜索参数
                that.loading = true;
                var page={
                    pageNo: that.currentPage,
                    pageSize : that.pageSize
                }
                var form = JSON.parse(JSON.stringify(that.form))


                if(isSearch) {
                    //删除空字符串
                    for (var key in form){
                        if(form[key] === undefined || form[key] === null){
                            delete  form[key]
                        }
                    }
                    form.sqlWhere ? data = Object.assign({}, {sqlWhere: form.sqlWhere}, page) : data = Object.assign({}, form, page)
                } else {
                    data = page;
                }
                sessionStorage.setItem(that.historyKey,JSON.stringify({form: form, page: page}));
                ms.http.post(ms.manager+"/game/user/list.do",data).then(
                    function(res) {
                        if (!res.result||res.data.total <= 0) {
                            that.emptyText ="暂无数据"
                            that.dataList = [];
                            that.total = 0;
                        } else {
                            that.emptyText = '';
                            that.total = res.data.total;
                            that.dataList = res.data.rows;
                        }
                        that.loading = false;
                    }).catch(function(err) {
                    that.loading = false;
                    console.log(err);
                });

            },
            //客户列表选中
            handleSelectionChange:function(val){
                this.selectionList = val;
            },
            //删除
            del: function(row){
                var that = this;
                that.$confirm("此操作将永久删除所选内容, 是否继续", "提示", {
                    confirmButtonText: "确认",
                    cancelButtonText: "取消",
                    type: 'warning'
                }).then(function() {
                    ms.http.post(ms.manager+"/game/user/delete.do", row.length?row:[row],{
                        headers: {
                            'Content-Type': 'application/json'
                        }
                    }).then(
                        function(res){
                            if (res.result) {
                                that.$notify({
                                    title:'成功',
                                    type: 'success',
                                    message:"删除成功"
                                });
                                //删除成功，刷新列表
                                that.list();
                            }else {
                                that.$notify({
                                    title: "错误",
                                    message: res.msg,
                                    type: 'warning'
                                });
                            }
                        });
                }).catch(function(err) {
                    //删除如果用户取消会抛出异常，所以需要catch一下
                    console.log(err)
                });
            },
            //新增
            save:function(id){
                if(id){
                    ms.util.openSystemUrl("/game/user/form.do?id="+id);
                }else {
                    ms.util.openSystemUrl("/game/user/form.do");
                }
            },

            //pageSize改变时会触发
            sizeChange:function(pagesize) {
                this.loading = true;
                this.pageSize = pagesize;
                this.list(true);
            },
            //currentPage改变时会触发
            currentChange:function(currentPage) {
                this.loading = true;
                this.currentPage = currentPage;
                this.list(true);
            },
            search:function(data){
                this.form.sqlWhere = JSON.stringify(data);
                this.list(true);
            },
            //重置表单
            rest:function(){
                this.currentPage = 1;
                this.form = {
                    sqlWhere:null
                };
                this.$refs.searchForm.resetFields();
                this.list(true);
            },
                   //区长  列表格式化
		selectCodesFormat:function(row, column, cellValue, index){
			var value="";
                        
			if(cellValue){
				var data = this.selectCodesOptions.find(function(value){
					return value.value==cellValue;
				})
				if(data&&data.label){
					value = data.label;
				}
			}

			return value;
		},

		//获取selectCodes数据源



        },
        mounted:function(){
            var that = this;

            //如果存在历史参数，恢复页面结果
            if(sessionStorage.getItem(this.historyKey) && ms.util.getParameter("isBack") == 'true') {
                var _history = JSON.parse(sessionStorage.getItem(this.historyKey))
                this.form = _history.form;
                this.total = parseInt(_history.total);
                this.currentPage = parseInt(_history.page.pageNo);
                this.pageSize = parseInt(_history.page.pageSize);
            }

            this.list(true);
        },
		created:function(){
			var that = this;
           
        }
    })
</script>
    <style scoped>
        #index .ms-container {
            height: calc(100vh - 141px);
        }
    </style>
